package com.baizhi.entity;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class User {
    private Integer id;
    private String name;
    private Integer age;

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public User(Integer id, String name, Integer age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public User() {
    }


    //练习 json 使用fastjson将list转换成json字符串
    public static void main(String[] args) {
        User u = new User(1,"admin",20);
        String s = JSON.toJSONString(u);
        System.out.println("user对象转换为JSON字符串："+s);

        List<User> list = new ArrayList<>();
        list.add(new User(2,"aaa",20));
        list.add(new User(3,"bbb",30));
        String s1 = JSON.toJSONString(list);
        System.out.println("list集合转换为JSON字符串："+s1);
        Map<String,User> map = new HashMap<>();
        map.put("80",new User(4,"zzz",30));
        map.put("90",new User(5,"sss",20));
        String s2 = JSON.toJSONString(map);
        System.out.println("map集合转换为JSON字符串："+s2);
    }
}
